package mysql

import (
	"github.com/go-xorm/xorm"
	"note/service/repository"
)

type districtsRepository struct {
	db *xorm.Engine
}

func NewDistrictsRepository(db *xorm.Engine) repository.DistrictsRepository {
	//_ = db.Sync2(new(districtsRepository))
	return &districtsRepository{db: db}
}

func (self *districtsRepository) InsertOne(doc *repository.Districts) (id int64, err error) {
	return self.db.InsertOne(doc)
}

func (self *districtsRepository) FindById(filter interface{}) (*repository.Districts, error) {
	doc := &repository.Districts{}
	_, err := self.db.Where("id=?", filter).Get(doc)
	return doc, err
}

func (self *districtsRepository) FindFilter(str string, args ...interface{}) ([]*repository.Districts, error) {
	var docs []*repository.Districts
	err := self.db.Where(str, args...).Find(&docs)
	return docs, err
}
